/**
 * 管理机
 */
import "reflect-metadata";
/**
 * 引入公共文件
 */
import "../common";
/**
 * 管理机的主要职责是 管理本脚本下的所有任务
 * 1. 管理UI任务
 * 2. 管理脚本任务
 * 3. 务必轻量
 */
import { container as injector } from 'tsyringe'
import { Timer } from "../autox/timer";
import { Task } from "../autox/task";
import { kwai, $ } from "../utils";
import { sendToWebsocket } from "../utils/send";

const timer = injector.resolve(Timer)
const task = injector.resolve(Task)

timer.setInterval(() => { }, 1000 * 10)

events.on('exit', () => {
    sendToWebsocket({ type: 'HEALTH_TASK_FINISH', payload: { pkg: $.PACKAGES["com.smile.gifmaker"] } })
    injector.dispose()
})

let count: number = 0;
try {
    const t = task.start(() => {
        kwai.openAndJoinVideoRoom()
        while (true) {
            try {
                count += 1;
                kwai.autoLookVideo()
                toastLog(`正在去下一条视频，总共看了${count}个视频`)
            } catch (e) {
                toastLog(e.message)
            } finally {
                $.swipeUp()
            }
        }
    });
    t.join(random(8 * 60 * 1000, 10 * 60 * 1000))
    t.interrupt()
} catch (e) {
    toastLog(e.message)
}
